#ifndef __INCLUDED_EVEREST_ODBC_RECORDSET_H
#define __INCLUDED_EVEREST_ODBC_RECORDSET_H

#include <everest/basedef.h>
#include <sql.h>
#include <sqlext.h>

BEGIN_NAMESPACE_EVEREST

namespace odbc
{
	class Statement;
	class Connection;
	enum  CursorType;

	class Recordset
	{
		EVEREST_UNCOPIABLE(Recordset)
		struct PData;

	public:
		enum MoveType
		{
			MOVE_ABSOLUTE = SQL_FETCH_ABSOLUTE,
			MOVE_RELATIVE = SQL_FETCH_RELATIVE
		};

	public:
		Recordset();
		virtual ~Recordset();

		int   open(Statement& stmt, CursorType cursorType);
		int   open(const char *pszSql, Connection& conn, CursorType cursorType);
		int   close();

		Connection* getConnection() const;
		CursorType  getCursorType() const;

		bool        moveNext();
		bool        movePrior();
		bool        moveFirst();
		bool        moveLast();
		bool        move(int num, MoveType mv);

		bool        getInt32(int colIndex, int& value) const;
		bool        getInt64(int colIndex, int64_t& value) const;
		bool        getFloat(int colIndex, float& value) const;
		bool        getDouble(int colIndex, double& value) const;
		bool        getString(int colIndex, String& value) const;
		bool        getBinary(int colIndex, ByteVector& value) const;
		bool        getDateTime(int colIndex, DateTime& value) const;
		bool        getTimestamp(int colIndex, Timestamp& value) const;

	protected:
		int         bind(Statement *pStmt);
		int         unbind(Statement *pStmt);

	protected:
		PData       *m_pData;
	};
	typedef CommonPtr<Recordset> RecordsetPtr;

} // end of namespace odbc

END_NAMESPACE_EVEREST


#endif // __INCLUDED_EVEREST_ODBC_RECORDSET_H
